#include "palette.hpp"
#include "error.hpp"

palette_c::~palette_c ( void )
{
        if ( NULL != levels )
        {
                for ( levels_v::iterator i = levels->begin (); i != levels->end (); i ++ )
                {
                        level_v * level = ( level_v * ) * i;
                        if ( NULL != level )
                        {
                                /*for ( level_v::iterator j = level->begin (); j != level->end (); j ++ )
                                {
                                        paths_v * paths = ( paths_v * ) * j;
                                        if ( NULL != paths )
                                        {
                                                delete paths;
                                        }
                                }*/
                                delete level;
                        }
                }
                delete levels;
        }
}

palette_c::palette_c ( long levels_count, long colours_count )
{
        throw_if ( levels_count < 1 || colours_count < 1, ERROR_INVALID_ARGUMENTS );
        levels = new levels_v ();
        levels->reserve ( levels_count );
        
        for ( long i = 0; i < levels_count; i ++ )
        {
                /*long level_k = colours_count;
                level_v * level = new level_v ();
                level->reserve ( level_k );
                for ( long j = 0; j < level_k; j ++ )
                {
                        paths_v * paths = new paths_v ( level_k + 1, 0 );
                        level->push_back ( paths );
                }*/
                level_v * level = new level_v ( colours_count, 0.0 );
                levels->push_back ( level );
        }
}

palette_c::palette_c ( const palette_c & right )
{
        throw ERROR_UNIMPLEMENTED;    
}

palette_c::paths_v * palette_c::get_paths ( long level, long colour )
{
        //return ( levels->at ( level ) )->at ( colour );
        return ( palette_c::paths_v * ) levels->at ( level );
}

long palette_c::get_levels_count () const
{
        return levels->size ();
}

